﻿Public Class vbTrade
    Dim C As classTrades
    Private Sub vbTrade_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        For Each Str As String In Form1.colSymbols
            txtSymbol.Items.Add(Str)
        Next
        For Each Str As String In Form1.colSystems
            txtSystem.Items.Add(Str)
        Next

        C = CType(Me.Tag, classTrades)
        txtComment.Text = C.Comment
        txtDirection.Text = C.Direction
        txtID.Text = C.ID
        txtPriceClose.Text = C.priceClose
        txtPriceOpen.Text = C.priceEnter
        txtSL.Text = C.SL
        txtTP.Text = C.TP
        txtStatus.Text = C.Status
        txtSymbol.Text = C.Symbol
        txtSystem.Text = C.System
        txtLotSize.Text = C.lotSize
        If Not C.picOpen Is Nothing Then picOpen.Image = C.picOpen
        If Not C.picClose Is Nothing Then picClose.Image = C.picClose
        txtRatio.Text = C.Ratio
    End Sub

    Private Sub vbTrade_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        C.Comment = txtComment.Text
        C.Direction = txtDirection.Text
        C.ID = txtID.Text
        C.Open = dateOpen.Value.Date
        C.Close = dateClose.Value.Date
        If Not picClose.Image Is Nothing Then C.picClose = picClose.Image.Clone
        If Not picOpen.Image Is Nothing Then C.picOpen = picOpen.Image.Clone
        C.priceClose = CDbl(txtPriceClose.Text)
        C.priceEnter = CDbl(txtPriceOpen.Text)
        C.SL = CDbl(Val(txtSL.Text))
        C.TP = CDbl(Val(txtTP.Text))
        C.Status = txtStatus.Text
        C.Symbol = txtSymbol.Text
        C.lotSize = CDbl(txtLotSize.Text)
        C.System = txtSystem.Text
        Me.Tag = C
    End Sub


    Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
        Me.Close()
    End Sub

    Private Sub txtTP_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTP.TextChanged
        If Val(txtTP.Text) <> 0 Then
            C.TP = Val(txtTP.Text)
            txtRatio.Text = C.Ratio
        End If
    End Sub

    Private Sub txtSL_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSL.TextChanged
        If Val(txtSL.Text) <> 0 Then
            C.SL = Val(txtSL.Text)
            txtRatio.Text = C.Ratio
        End If
    End Sub

    Private Sub cmdPicOpenCapture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPicOpenCapture.Click
        Dim frm As New frmCapture
        frm.pForm = Me
        frm.ShowDialog()
        If Not frm.Tag Is Nothing Then
            picOpen.Image = CType(frm.Tag, Bitmap)
        End If
    End Sub
End Class